package com.jiyinit.web.core.mobile.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jiyinit.web.core.mobile.dto.ExchangeRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.jiyinit.core.framework.base.paging.PagingResult;
import com.jiyinit.core.framework.dao.mybatis.base.MybatisDaoContext;
import com.jiyinit.core.framework.dao.mybatis.paginator.domain.PageBounds;
import com.jiyinit.web.core.mobile.dto.ExchangeCommentRequest;
import com.jiyinit.web.core.mobile.entity.TabCoreExchangeCommentEntity;

@Repository("core.tabCoreExchangeCommentDao")
public class TabCoreExchangeCommentDao {

	private String SQLID = "core.tabCoreExchangeCommentDao.";

	@Autowired
	@Qualifier("core.MybatisDaoContext")
	private MybatisDaoContext mybatisDaoContext;
	
	/**
     * 多条件分页查询
     * @param request
     * @return
     */
    public PagingResult<TabCoreExchangeCommentEntity> findForPage(ExchangeCommentRequest request) {
        PageBounds pageBounds = new PageBounds();
        pageBounds.setLimit(request.getLimit());
        pageBounds.setPage(request.getPage());
        return mybatisDaoContext.findForPage(SQLID + "findForPage", TabCoreExchangeCommentEntity.class, request.toMap(), pageBounds);
    }
    
    /**
     * id查询
     * @param id
     * @return
     */
    public TabCoreExchangeCommentEntity findOne(Integer id){
    	return mybatisDaoContext.findOne(SQLID + "findOne", TabCoreExchangeCommentEntity.class, id);
    }

    /**
     * 添加
     * @param entity
     * @return
     */
	public int add(TabCoreExchangeCommentEntity entity) {
		return mybatisDaoContext.save(SQLID+ "add", entity);
	}
	
	/**
     * 修改
     * @param entity
     * @return
     */
	public int update(TabCoreExchangeCommentEntity entity) {
		return mybatisDaoContext.update(SQLID+ "update", entity);
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	public int delete(Integer id){
		Map<String, Object> map = new HashMap<>();
		map.put("id", id);
		return mybatisDaoContext.update(SQLID+ "delete", map);
	}

	/**
	 * 查询点赞
	 * @param entity
	 * @return
	 */
	public int find(TabCoreExchangeCommentEntity entity) {

		return mybatisDaoContext.findOne(SQLID+"find",Integer.class,entity);
	}

	/**
	 * 查询帖子详情
	 * @param request
	 * @return
	 */
	public PagingResult<TabCoreExchangeCommentEntity> historyList(ExchangeCommentRequest request) {
		PageBounds pageBounds = new PageBounds();
		pageBounds.setLimit(request.getLimit());
		pageBounds.setPage(request.getPage());
		return mybatisDaoContext.findForPage(SQLID + "historyList", TabCoreExchangeCommentEntity.class, request.toMap(), pageBounds);
	}

	public int deleteByUserId(TabCoreExchangeCommentEntity entity) {
		return mybatisDaoContext.update(SQLID+ "deleteByUserId", entity);
	}
}
